package com.aegean.MonitorExamSYS.examinee.action;

import java.awt.event.AWTEventListener;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.examinee.business.ExamineeBusiness;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.opensymphony.xwork2.ActionSupport;
@Controller("UserUpdatePwd")
@Scope("prototype")
public class UserUpdatePwd extends ActionSupport{
	@Resource
	ExamineeBusiness business;
	HttpSession session=ServletActionContext.getRequest().getSession();
	private ExamineeValue user;
    private String user_Pwd;
    private String newPwd1;
    private String newPwd2;
	public ExamineeValue getUser() {
		return user;
	}

	public void setUser(ExamineeValue user) {
		this.user = user;
	}

	public String getUser_Pwd() {
		return user_Pwd;
	}

	public void setUser_Pwd(String user_Pwd) {
		this.user_Pwd = user_Pwd;
	}

	public String getNewPwd1() {
		return newPwd1;
	}

	public void setNewPwd1(String newPwd1) {
		this.newPwd1 = newPwd1;
	}

	public String getNewPwd2() {
		return newPwd2;
	}

	public void setNewPwd2(String newPwd2) {
		this.newPwd2 = newPwd2;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		user=(ExamineeValue) session.getAttribute("UserLogin");
		user=business.updateUserPwd(user.getUser_Id(), newPwd1);
		session.setAttribute("UserLogin",user);
		return SUCCESS;
	}

	@Override
	public void validate() {
		// TODO Auto-generated method stub
		user=(ExamineeValue) session.getAttribute("UserLogin");
		if(!user_Pwd.trim().equals(user.getUser_Password().trim())){
			this.addFieldError("user_Pwd","对不起，用户原密码不正确！");
		}else if(user_Pwd.trim().equals(newPwd1.trim())){
			this.addFieldError("newPwd1", "对不起，您的密码和以前一致，无需修改！");
		}
		
	}

}
